package com.youdianstar.app.ui

import androidx.lifecycle.viewModelScope

import com.youdianstar.app.common.base.BaseViewModel
import com.youdianstar.app.common.entity.FileUpResult
import com.youdianstar.app.common.event.NetStateLiveData
import com.youdianstar.app.entity.ReportBefore
import com.youdianstar.app.entity.ReportFaultyReq
import com.youdianstar.app.entity.ReportOrderReq
import com.youdianstar.app.support.ApiRepository
import kotlinx.coroutines.launch


/**
 * File: ReportViewModel
 * Author: 82149 Create: 2021/10/28 15:22
 * Changes (from 2021/10/28)
 * --------------------------------------------------
 * description: 上报相关
 * ---------------------------------------------------
 *
 */
class ReportViewModel (private val repo: ApiRepository) : BaseViewModel() {

    val fileUpLoadLiveData = NetStateLiveData<FileUpResult>()

    val fileDeleteLiveData = NetStateLiveData<Any>()

    val reportResultLiveData = NetStateLiveData<Any>()

    /*上传图片*/
    fun upLoadImage(path: String){
        showLoading()
        viewModelScope.launch {
            repo.upLoadImage(path,fileUpLoadLiveData)
        }
    }

    /*删除服务端图片*/
    fun deleteImage(url:String){
        viewModelScope.launch {
            repo.deleteImage(url,fileDeleteLiveData)
        }
    }

    /**
     * 报损
     * @param damageReq 报损对象
     */
    fun reportFault(damageReq: ReportFaultyReq){
        showLoading()
        viewModelScope.launch {
            repo.reportFault(damageReq,reportResultLiveData)
        }
    }

    /**
     * 报订单问题
     * @param orderReq 请求对象
     */
    fun reportOrderFailed(orderReq: ReportOrderReq){
        showLoading()
        viewModelScope.launch {
            repo.reportOrder(orderReq,reportResultLiveData)
        }
    }


    val reportBeforeLiveData = NetStateLiveData<ReportBefore>()
    /**
     * 报订单问题-前置确认
     *
     * @param orderNo 订单号
     */
    fun reportBeforeCheck(orderNo : String){
        viewModelScope.launch {
            repo.reportOrderCheck(orderNo,reportBeforeLiveData)
        }
    }


}